﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace CobaCoba
{
    [Serializable, ProtoBuf.ProtoContract, DataContract]
    public class AckInstruction : ImessageContent
    {
        private DateTime _settlementDate;
        private DateTime _inTradeDate;
        private string _instructionType = "AckInstruction";

        public override Type GetClassType()
        {
            return this.GetType();
        }

        [ProtoBuf.ProtoIgnore]
        public override string TypeIncomingClassName
        {
            get { return "AckInstruction"; }
        }

        [ProtoBuf.ProtoMember(1)]
        [ElementIn(1, "externalReference")]
        [DataMember]
        public override string ExternalReference
        {
            get { return base.ExternalReference; }
            set { base.ExternalReference = value; }
        }

        [ProtoBuf.ProtoMember(2)]
        [DataMember]
        public override DateTime InTradeDate
        {
            get { return _inTradeDate; }
            set { base.InTradeDate = _inTradeDate = value; }
        }

        [ProtoBuf.ProtoIgnore]
        [ElementIn(2, "tradeDate")]
        public virtual string TradeDate
        {
            get
            {
                return ((DateTime)_inTradeDate).ToString("yyyyMMdd");
            }
            set
            {
                _inTradeDate = CommonUtil.ConvertStringToDateTime(value);
            }
        }

        [ProtoBuf.ProtoMember(3)]
        [DataMember]
        public override DateTime InSettlementDate
        {
            get { return _settlementDate; }
            set { _settlementDate = value; }
        }

        [ProtoBuf.ProtoIgnore]
        [ElementIn(3, "settlementDate")]
        public string SettlementDate
        {
            get
            {
                return ((DateTime)_settlementDate).ToString("yyyyMMdd");
            }
            set
            {
                _settlementDate = CommonUtil.ConvertStringToDateTime(value);
            }
        }

        [ProtoBuf.ProtoMember(4)]
        [ElementIn(4, "error")]
        [DataMember]
        public List<ListErrorRecord> Error
        {
            get;
            set;
        }

        [ProtoBuf.ProtoIgnore]
        [DataMember]
        public override string InstructionType
        {
            get
            {
                return _instructionType;
            }
            set
            {
                base.InstructionType = _instructionType;
            }
        }

        [ProtoBuf.ProtoMember(6)]
        [DataMember]
        public override string Status
        {
            get
            {
                return base.Status;
            }
            set
            {
                base.Status = value;
            }
        }

        [ProtoBuf.ProtoMember(7)]
        [DataMember]
        public override string SecurityCode
        {
            get
            {
                return base.SecurityCode;
            }
            set
            {
                base.SecurityCode = value;
            }
        }

    }

    [Serializable, ProtoBuf.ProtoContract, DataContract]
    public class ListErrorRecord : ICloneable
    {
        private string _errorCode = string.Empty;
        private string _errorMessage = string.Empty;

        public object Clone()
        {
            return this.MemberwiseClone();
        }

        [ProtoBuf.ProtoMember(1)]
        [ElementOutgoing(1, "errorCode")]
        [DataMember]
        public string ErrorCode
        {
            get { return _errorCode; }
            set { _errorCode = value; }
        }

        [ProtoBuf.ProtoMember(2)]
        [ElementOutgoing(2, "errorMessage")]
        [DataMember]
        public string ErrorMessage
        {
            get { return _errorMessage; }
            set { _errorMessage = value; }
        }
    }
}
